package com.xyhuo.leetcode;

import java.util.*;


public class FindMatrix {

    public List<List<Integer>> findMatrix(int[] nums) {
        Map<Integer, Integer> map = new HashMap<>();
        int height = 0;
        for (int num : nums) {
            int tmp = 1;
            if (map.containsKey(num)) {
                tmp = map.get(num) + 1;
            }
            map.put(num, tmp);
            if (tmp > height)
                height = tmp;
        }

        List<List<Integer>> result = new ArrayList<>();
        for (int i = 0; i < height; i++) {
            List<Integer> list = new ArrayList<>();
            result.add(list);

            for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
                if (i < entry.getValue()) {
                    list.add(entry.getKey());
                }
            }
        }
        return result;
    }

}
